<template>
  <div class="container">
    <van-pull-refresh style="min-height: 100vh;" v-model="loading" @refresh="onRefresh" success-text="刷新成功">
      <div class="container-item" v-for="(item,index) in list" :key="index">
        <van-cell-group inset>
          <van-cell :title=item.name :label=item.address />
        </van-cell-group>
      </div>
      <div class="container-btn">
        <van-button block type="primary" size="normal" @click="onAddClick">添加地址</van-button>
      </div>
    </van-pull-refresh>
    <router-view></router-view>
  </div>
</template>

<script lang="ts" setup>
import { ref,onMounted,inject } from 'vue'
import { Toast } from 'vant'
import router from '@/router/index'  
import { getAddressList } from '@/localhttp/loginApi'
const global = inject('global')
 
const loading = ref(false);
const onRefresh = () => {
  setTimeout(() => { 
    loading.value = false; 
  }, 1000);
};

const onAddClick = () => { 
   router.push({ name: "addressEdit" }); 
};
const list = ref<any[]>([])
onMounted(async () => {  
  console.log('global======inject=====>',global) 
  const ret = await getAddressList();
  list.value = ret.data; 
})
  
const onEdit = () => {
  Toast('编辑地址')
};

</script>

<style lang="scss" scoped>
.container {
  overflow: auto;
  padding: 10px 0px; 
  &-item {
    padding: 7px 0px;
  }
  &-btn {
    padding: 7px 10px;
  }
}
</style>
